class Entity {
    image;
    isLoaded: boolean;
    state;
    scale: number;
    pos;
    last;
    interpolate_diff;
    collision_radius;
    frames;
    currentframe: number;
    flipped: boolean;
    isDead: boolean;

    constructor() {
        this.init();
    }

    init() {
        //used to setup an entity(many used for future implementation)
        this.image = null; //image used to draw
        this.isLoaded = false;   //is Entity loaded
        this.state = null;       //current state of the object

        this.scale = 1;          //scale to draw at
        this.pos = { x: 0, y: 0, angle: 0 }, //position of the object
        this.last = { x: 0, y: 0, angle: 0 }, //last position of object
        this.interpolate_diff = { x: 0, y: 0, angle: 0 }; //difference between last and current position
        this.collision_radius = 0; //radius to use for collisions

        this.frames = [];      //array of frames for animation and drawing
        this.currentframe = 0; //current animation frame
        this.flipped = false;  //should the image be drawn flipped

        this.isDead = false;
    }

    update_pre() {
        //interpolation setup
        this.last.x = this.pos.x;
        this.last.y = this.pos.y;
        this.last.angle = this.pos.angle;

    }

    update() {
    }

    update_post() {
        //interpolation 
        this.interpolate_diff.x = this.pos.x - this.last.x;
        this.interpolate_diff.y = this.pos.y - this.last.y;
        this.interpolate_diff.angle = this.pos.angle - this.last.angle;

    }

    draw() {
        this.frames[this.currentframe].draw(window.game.Entity.interpolate.apply(this, ['x']), window.game.Entity.interpolate.apply(this, ['y']), this.image, window.game.Entity.interpolate.apply(this, ['angle']), this.flipped, this.scale);
    }

    loadimg(path) {
        var image = new Image();
        image.src = path;
        return image;
    }

    interpolate(axis) {
        if (axis === 'x' || axis === 'X') {
            return this.last.x + (this.interpolate_diff.x * window.game.system.interpolationvalue);
        }
        else if (axis === 'y' || axis === 'Y') {
            return this.last.y + (this.interpolate_diff.y * window.game.system.interpolationvalue);
        }
        else {
            return this.last.angle + (this.interpolate_diff.angle * window.game.system.interpolationvalue);

        }
    }

    normalizevector(x, y) {
        if (x === 0 && y === 0) //check for degenerate case
        { return { x: 0, y: 0 }; }

        //calculate length
        var length = Math.sqrt((x * x) + (y * y));
        //divide components by length
        return { x: x / length, y: y / length };
    }

    vectorlength(vector) {

        return Math.sqrt((vector.x * vector.x) + (vector.y * vector.y));
    }
}